package smedi.ismedi.mobile.bff.controller.securityman;

import com.smedi.ismedi.securityman.api.dto.request.*;
import com.smedi.ismedi.securityman.api.dto.response.AddOfficerListResultResponse;
import com.smedi.ismedi.securityman.api.dto.response.FileResponse;
import com.smedi.ismedi.securityman.api.dto.response.OfficerManagementResponse;
import com.smedi.ismedi.securityman.api.feign.RemoteOfficerManagementFeignApi;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * 干事管理
 *
 * @author xuyuanqiao
 * @date 2021/09/23
 */
@Slf4j
@Api(value = "干事管理接口", tags = {"干事管理接口"})
@RequestMapping(value = "/mobilebff/v1/OfficerManagement")
@RestController
@AllArgsConstructor
public class OfficerManagementController {
    private final RemoteOfficerManagementFeignApi remoteOfficerManagementFeignApi;

    /**
     * 添加干事记录
     *
     * @param addOfficerManagementRequest 添加干事记录请求
     * @return ResponseData<OfficerManagementResponse>
     */
    @ApiOperation(httpMethod = "POST", value = "添加干事记录")
    @PostMapping(value = "/add")
    ResponseData<OfficerManagementResponse> postAddOfficerManagement(@Validated @RequestBody AddOfficerManagementRequest addOfficerManagementRequest) {
        return remoteOfficerManagementFeignApi.postAddOfficerManagement(addOfficerManagementRequest);
    }

    /**
     * 删除干事记录
     *
     * @param officerManagementId 干事记录id
     * @return ResponseData<Long>
     */
    @ApiOperation(httpMethod = "DELETE", value = "删除干事记录")
    @DeleteMapping(value = "/delete")
    ResponseData<Long> deleteOfficerManagement(@RequestParam(value = "officerManagementId") Long officerManagementId) {
        return remoteOfficerManagementFeignApi.deleteOfficerManagement(officerManagementId);
    }

    /**
     * 分页查询干事记录
     *
     * @param officerManagementPageRequest 查询干事记录请求
     * @return ResponseData<PaginationData < OfficerManagementResponse>>
     */
    @ApiOperation(httpMethod = "POST", value = "分页查询干事记录")
    @PostMapping(value = "/pageList")
    ResponseData<PaginationData<OfficerManagementResponse>> getOfficerManagementPage(@Validated @RequestBody OfficerManagementPageRequest officerManagementPageRequest) {
        return remoteOfficerManagementFeignApi.getOfficerManagementPage(officerManagementPageRequest);
    }

    /**
     * 通过文件导入添加干事记录
     *
     * @param file        excel文件，包含了需要导入的劳务人员
     * @param projectId   项目id
     * @param projectName 项目名称
     * @return ResponseData<List < String>>
     * @throws IOException
     */
    @ApiOperation(value = "通过文件导入添加干事记录", nickname = "通过文件导入添加干事记录", httpMethod = "POST", response = ResponseData.class)
    @PostMapping(value = "/addList", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    ResponseData<List<AddOfficerListResultResponse>> postImportAddOfficerManagement(@ApiParam(value = "file", required = true) @RequestPart(value = "file", required = true) MultipartFile file,
                                                                                    @RequestParam(value = "projectId", required = true) Long projectId,
                                                                                    @RequestParam(value = "projectName", required = true) String projectName) throws IOException {
        return remoteOfficerManagementFeignApi.postImportAddOfficerManagement(file, projectId, projectName);
    }

    /**
     * 压缩包下载
     *
     * @param filesToZipRequest 通过压缩包下载请求
     * @return ResponseEntity<byte [ ]>
     */
    @ApiOperation(httpMethod = "POST", value = "压缩包下载")
    @PostMapping(value = "/download")
    ResponseEntity<byte[]> postDownloadFilesToZip(@Validated @RequestBody FilesToZipRequest filesToZipRequest) throws IOException {
        return remoteOfficerManagementFeignApi.postDownloadFilesToZip(filesToZipRequest);
    }

    /**
     * 干事返岗
     *
     * @param officerManagementId 干事id
     * @param statue              干事状态 0：离岗  1：返岗
     * @return ResponseData<Boolean>
     */
    @ApiOperation(httpMethod = "GET", value = "干事返岗")
    @GetMapping(value = "/backWork")
    ResponseData<Boolean> getBackWork(@RequestParam(value = "officerManagementId") @ApiParam(value = "干事id") Long officerManagementId,
                                      @RequestParam(value = "statue") @ApiParam(value = "干事状态 0：离岗  1：返岗") Long statue) {
        return remoteOfficerManagementFeignApi.getBackWork(officerManagementId, statue);
    }

    ;

    /**
     * 下载导入候选人附件模板
     *
     * @return ResponseEntity<byte [ ]>
     */
    @ApiOperation(httpMethod = "POST", value = "下载导入候选人附件模板")
    @PostMapping(value = "/downloadTemplate")
    ResponseEntity<byte[]> postDownloadTemplate() throws IOException {
        return remoteOfficerManagementFeignApi.postDownloadTemplate();
    }


    /**
     * 干事、培训、考核的导出
     *
     * @return ResponseEntity<byte [ ]>
     */
    @ApiOperation(httpMethod = "POST", value = "干事、培训、考核的导出")
    @PostMapping(value = "/exportDetail")
    ResponseEntity<byte[]> postExportDetail(@Validated @RequestBody @ApiParam(value = "需要导出的记录id集合") List<Long> ids,
                                            @RequestParam(value = "type", required = true) @ApiParam(value = "【0:导出干事列表】  【1：导出培训记录】  【2：导出考核记录】") String type
    ) throws IOException {
        return remoteOfficerManagementFeignApi.postExportDetail(ids, type);

    }

    /**
     * 分页查询干事记录移动端
     *
     * @param mobileOfficerManagementPageRequest 查询干事记录请求
     * @return ResponseData<PaginationData < OfficerManagementResponse>>
     */
    @ApiOperation(httpMethod = "POST", value = "分页查询干事记录移动端")
    @PostMapping(value = "/mobilePageList")
    ResponseData<PaginationData<OfficerManagementResponse>> getMobileOfficerManagementPage(@Validated @RequestBody MobileOfficerManagementPageRequest mobileOfficerManagementPageRequest) {
        return remoteOfficerManagementFeignApi.getMobileOfficerManagementPage(mobileOfficerManagementPageRequest);
    }

    @ApiOperation(httpMethod = "POST", value = "干事考核表导出(url)")
    @PostMapping(value = "/exportOfficerAssessment")
    ResponseData<FileResponse> exportOfficerAssessment(@Validated @RequestBody exportOfficerAssessmentRequest exportOfficerAssessmentRequest) throws IOException{
        return remoteOfficerManagementFeignApi.exportOfficerAssessment(exportOfficerAssessmentRequest);
    }

}
